package com.ibiaoke.boss.controller;

import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.response.Res;
import com.ibiaoke.order.entity.so.OrderSO;
import com.ibiaoke.order.entity.so.PtOrderSO;
import com.ibiaoke.order.entity.vo.DateAnalysisVO;
import com.ibiaoke.order.entity.vo.OrderVO;
import com.ibiaoke.order.service.OrderService;
import com.ibiaoke.order.service.XcxOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * boss订单controller
 * Created by huhaichao on 2017/6/8.
 */
@Controller
public class BossOrderController {

    @Autowired
    private OrderService orderService;



    /**
     * 查询订单列表
     *
     * @return
     */
    @RequestMapping("listOrder")
    @ResponseBody
    public Res listOrder(OrderSO orderSO, Page page) {
        List<OrderVO> orders = orderService.listOrder(orderSO, page);
        return Res.create().addResponse("orders", orders).addResponse("page", page);
    }


    /**
     * 获取订单详情
     *
     * @param orderId
     * @return
     */
    @RequestMapping("getOrder")
    @ResponseBody
    public Res getOrder(Integer orderId) {
        OrderVO order = orderService.getOrder(orderId);
        return Res.create().addResponse("orderDetail", order);
    }


    /**
     * 发货
     *
     * @param orderId
     * @return
     */
    @RequestMapping("deliverOrder")
    @ResponseBody
    public Res deliverOrder(Integer orderId) {
        orderService.deliverOrder(orderId);
        return Res.create();
    }

    /**
     * 获取当天对应门店的销售详情
     *
     * @param orderSO
     * @return
     */
    @RequestMapping("/getDateAnalysisToday")
    @ResponseBody
    public Res getDateAnalysisToday(OrderSO orderSO,PtOrderSO ptOrderSO) {
        HashMap<String, DateAnalysisVO> dateAnalysisVO = orderService.getTodayOrderData(orderSO,ptOrderSO, null);
        return Res.create().addResponse("dateAnalysisVO", dateAnalysisVO);
    }


    /**
     * 根据传入时间来查询对应门店的历史销售详情
     *
     * @param orderSO
     * @return
     */
    @RequestMapping("/getDateAnalysisByDate")
    @ResponseBody
    public Res getDateAnalysisByDate(OrderSO orderSO, PtOrderSO ptOrderSO) {
        HashMap<String, DateAnalysisVO> dateAnalysisVO = orderService.getOrderAnalysis(orderSO, ptOrderSO,null);
        return Res.create().addResponse("dateAnalysisVO", dateAnalysisVO);
    }

    @RequestMapping("/aggregate")
    @ResponseBody
    public Res aggregate(Integer serviceNum, Date startTime, Date endTime) {
        String bounty = orderService.aggregate(serviceNum, startTime, endTime);
        return Res.create().addResponse("bounty",bounty);
    }
}
